package com.bw.mylogger.impl;

import android.util.Log;

import com.bw.mylogger.LoggerInterface;
import com.bw.mylogger.common.LoggerLevel;

public class LogcatImpl implements LoggerInterface {
    private String TAG = "";
    private boolean isOpen = false;
    private LoggerLevel lowestLevel;
    private String template = "[BW LOG: %s --> @s]";
    @Override
    public void debug(String tag, String log) {
        if(isOpen&&LoggerLevel.Debug.ordinal() >= lowestLevel.ordinal()){
            Log.d(TAG, String.format(template,tag,log));
        }
    }

    @Override
    public void info(String tag, String log) {
        if(isOpen&&LoggerLevel.Info.ordinal() >= lowestLevel.ordinal()){
            Log.d(TAG, String.format(template,tag,log));
        }
    }

    @Override
    public void warning(String tag, String log) {
        if(isOpen&&LoggerLevel.Warning.ordinal() >= lowestLevel.ordinal()){
            Log.d(TAG, String.format(template,tag,log));
        }
    }

    @Override
    public void error(String tag, String log) {
        if(isOpen&&LoggerLevel.Error.ordinal() >= lowestLevel.ordinal()){
            Log.d(TAG, String.format(template,tag,log));
        }
    }

    @Override
    public void isOpen(boolean _isOpen) {
        isOpen = _isOpen;
    }

    @Override
    public void setTag(String tag) {
        this.TAG = tag;
    }

    @Override
    public void lowestLevel(LoggerLevel level) {
        this.lowestLevel = level;
    }
}
